/**
 * @format
 * @Author: TC
 * @Date: 2025-05-05 01:16:16
 * @Last Modified by: TC
 * @Last Modified time: 2025-06-17 13:54:19
 */

import { _decorator, Button, Component, EventTouch, Node } from "cc";
import { app } from "db://assets/FrameWork/App";
import { BaseUI } from "db://assets/FrameWork/Module/Component/BaseUI";
import { EUIConst } from "../../Const/UIConst";
import { nsLoadingInterface } from "../Loading/Interface/LoadingInterface";
import { myGame } from "../../MyGame";
const { ccclass, property } = _decorator;

/**
 * 主界面
 */
@ccclass("MainUI")
export class MainUI extends BaseUI {
    @property({ type: Button, displayName: "排行榜按钮" })
    btnRank: Button = null;
    @property({ type: Button, displayName: "设置按钮" })
    btnSetting: Button = null;
    @property({ type: Button, displayName: "更多按钮" })
    btnMore: Button = null;
    @property({ type: Button, displayName: "开始按钮" })
    btnStart: Button = null;

    protected addUIEvent(): void {
        super.addUIEvent();
        this.addClickEvent(this.btnRank, this.onRank);
        this.addClickEvent(this.btnSetting, this.onSetting);
        this.addClickEvent(this.btnMore, this.onMore);
        this.addClickEvent(this.btnStart, this.onStart);
    }

    /**
     * 点击更多游戏
     */
    onMore(): void {
        app.sdkMgr.showMore();
    }

    /**
     * 点击开始
     */
    onStart(): void {
        // app.sceneMgr.runScene("RoleTestScene2D");
        // app.rapierMgr.init(() => {
        //     this.closeUI();
        //     app.uiMgr.openUI(EUIConst.BattleUI);
        // });
        this.closeUI();
        const data: nsLoadingInterface.IFullLoadingUIData = {
            taskList: myGame.preloadMgr.gameList,
            completeCb: function (): void {
                app.uiMgr.openUI(EUIConst.BattleUI);
            },
            name: "",
        };
        app.uiMgr.openUI(EUIConst.FullLoadingUI, data);
    }

    /**
     * 点击设置
     */
    onSetting(): void {
        app.uiMgr.openUI(EUIConst.SettingUI);
    }

    /**
     * 点击排行榜
     */
    onRank(): void {
        app.sdkMgr.showRank();
    }
}
